package edu.pitt.dbmi.odie.gapp.gwt.client.analysis.datasource;

import com.smartgwt.client.data.DSRequest;
import com.smartgwt.client.data.DataSource;
import com.smartgwt.client.data.fields.DataSourceDateField;
import com.smartgwt.client.data.fields.DataSourceIntegerField;
import com.smartgwt.client.data.fields.DataSourceTextField;

public class ODIE_AnalysisTestDataSource extends DataSource {

	private static ODIE_AnalysisTestDataSource instance = null;

	public static ODIE_AnalysisTestDataSource getInstance() {
		if (instance == null) {
			instance = new ODIE_AnalysisTestDataSource("analysisLocalDS");
		}
		return instance;
	}

	public ODIE_AnalysisTestDataSource(String id) {

		setID(id);

		DataSourceIntegerField primaryKeyField = new DataSourceIntegerField(
				"id");
		primaryKeyField.setHidden(true);
		primaryKeyField.setPrimaryKey(true);

		DataSourceTextField odieIdField = new DataSourceTextField("odieId",
				"odieId", 5, false);
		odieIdField.setHidden(true) ;
		
		DataSourceTextField userIdField = new DataSourceTextField("userId",
				"userId", 5, false);
		userIdField.setHidden(true) ;
		
		DataSourceTextField titleField = new DataSourceTextField("title",
				"title", 45, false);
		
		DataSourceTextField analysisStatusField = new DataSourceTextField(
				"analysisStatus", "status", 15, false);
		
		DataSourceDateField creationDateField = new DataSourceDateField(
				"creationDate", "created", 10, false);
		creationDateField.setHidden(true);
		
		DataSourceDateField modifiedDateField = new DataSourceDateField(
				"modifiedDate", "modified", 10, false);
		modifiedDateField.setHidden(true);
		
		DataSourceIntegerField unitsRequestedField = new DataSourceIntegerField(
				"unitsRequested", "requested", 3, false);
//		unitsRequestedField.setDetail(true) ;
//		unitsRequestedField.setCanEdit(false) ;
//		unitsRequestedField.setCanSortClientOnly(false) ;
//		unitsRequestedField.setLength(5) ;
		
		DataSourceIntegerField unitsCompletedField = new DataSourceIntegerField(
				"unitsCompleted", "completed", 3, false);
//		unitsCompletedField.setDetail(true) ;
//		unitsCompletedField.setCanEdit(false) ;
//		unitsCompletedField.setCanSortClientOnly(false) ;
//		unitsCompletedField.setLength(5) ;
		
		DataSourceTextField processingUnitNameField = new DataSourceTextField(
				"processingUnitName", "processing", 45, false);
		processingUnitNameField.setHidden(true);
		
		DataSourceTextField progressField = new DataSourceTextField(
				"progress", "progress", 100, false);
//		progressField.setDetail(false) ;
//		progressField.setCanEdit(false) ;
//		progressField.setCanSortClientOnly(false) ;
//		progressField.setLength(100) ;
		
		setFields(primaryKeyField, odieIdField, userIdField, titleField,
				analysisStatusField, creationDateField, modifiedDateField,
				unitsRequestedField, unitsCompletedField, processingUnitNameField,
				progressField);

		setClientOnly(true);
		
		setTestData(ODIE_AnalysisData.getRecords());
	}

	protected Object transformRequest(DSRequest dsRequest) {
		return super.transformRequest(dsRequest);
	}
}
